package com.bjpowernode.other.volitale;

/**
 *
 */
public class volatile01 {

    //保证内存可见性
    private static volatile boolean flag = true;

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            //这里的子线程会读取本地缓存的flag值
            while (flag) {

            }
            System.out.println("结束");
        }).start();

        Thread.sleep(1000);
        flag = false;
    }
}
